<?php

namespace Muyuxuan\ThreePayment\tools;

trait ConfigTrait
{
    protected $message;//错误信息
    protected $isTest = false;//是否测试环境
    protected $report_errors = true;//是否报错
    public function __construct($config=[])
    {
        if(!empty($config)){
            $this->config = array_replace_recursive($this->config,$config);
        }
        if(method_exists($this,'initConfig')){
            $this->initConfig();
        }
    }

    /**
     * 获取错误信息
     * @return mixed
     */
    public function getMessage()
    {
        return $this->message;
    }

    /**
     * 设置测试环境
     * @param $bool
     * @return void
     */
    public function setTest($bool=false)
    {
        $this->isTest = $bool;
    }

    /**
     * 错误处理
     * @param $msg
     * @return false
     * @throws \Exception
     */
    public function error($msg='')
    {
        if($this->report_errors){
            throw new \Exception($msg);
        }
        $this->message = $msg;
        return false;
    }
}